package com.yonyou.cloud.member.libs.key;

import com.yonyou.cloud.member.domainmodel.vo.EntityId;

import java.time.Instant;
import java.util.concurrent.atomic.AtomicLong;

public class MockKeyGeneratorImpl implements KeyGenerator {
    private static final AtomicLong counter = new AtomicLong(Instant.now().toEpochMilli());
    KeyRegistry keyRegistry;

    public MockKeyGeneratorImpl(KeyRegistry keyRegistry) {
        this.keyRegistry = keyRegistry;
    }

    @Override
    public <U extends EntityId> U generate(Class<U> clazz) {
        long l = counter.incrementAndGet();
        return keyRegistry.createKey(clazz, l);
    }
}